package reivew;

import java.util.Scanner;

public class Waimai {
    public static void main(String[] args) {
        String[] names = new String[4];
        String[] dishMegs = new String[4];
//        菜品名和份数
        int[] times = new int[4];
//        送餐时间
        String[] addresses = new String[4];
//        送餐地址
        int[] states = new int[4];
//        订单状态，可以用boolean进行判断
        double[] sumPrices = new double[4];
//        餐品总价格
        String[] dishNames = {"红烧带鱼", "鱼香肉丝", "时令鲜蔬"};
        double[] dishPrice = {38.0, 20.0, 10.0};
        int[] dianzan = new int[3];

        Scanner sc = new Scanner(System.in);
        int in = 0;
        System.out.println("欢迎使用吃货联盟系统");
        System.out.println("********************");
        do {
            System.out.println("1:我要订餐");
            System.out.println("2：查看餐袋");
            System.out.println("3：签收订单");
            System.out.println("4：删除订单");
            System.out.println("5：我要点赞");
            System.out.println("6：退出系统");
            System.out.println("选择你想要的服务应输入数字：");
            int num = sc.nextInt();
            switch (num) {
                case 1: {
                    System.out.println("***我要订餐***");
                    System.out.println("输入订餐人姓名");
                    boolean isadd = true;//标记是否已满
                    for (int i = 0; i < names.length; i++) {
                        if (names[i] == null) {
                            names[i] = sc.next();
                            break;
                        } else {
                            System.out.println("序号" + " " + "菜名" + " " + "价格"+"点赞");
                            for (int j = 0; j < dishNames.length; j++) {
                                System.out.println(j+ 1 + " " + dishNames[j] + " " + dishPrice[j]+" "+dianzan[j]);
                            }
                            System.out.println("请输入您要点的菜品编号");
                            int chooseDish = sc.nextInt();
                            System.out.println("请输入那你需要的份数：");
                            int number = sc.nextInt();
                            String dishMeg = dishNames[chooseDish - 1] + " " + number + "份";
                            double sumPrice = dishPrice[chooseDish - 1] * num;

                            double deliCharge = (sumPrice >= 50) ? 0 : 5;
                            System.out.println("餐费" + sumPrice + "元,送餐费" + deliCharge + "元，总计:" + (sumPrice + deliCharge) + "元。");

                            System.out.println("选择送餐时间");
                            int eatTime = sc.nextInt();
                            if (eatTime < 8 | eatTime > 20) {
                                System.out.println("输入错误，重新输入");
                            } else {
                                eatTime = sc.nextInt();
                                System.out.println("可以送餐");
                            }
                            System.out.println("输入送餐地址：");
                            String address = sc.next();
                            System.out.println("订餐成功");
                            System.out.println("您订的是：" + dishNames[chooseDish - 1] + number + "份" + "" + "送餐时间" + eatTime + "点" + "" + "餐费" + sumPrices + "元" + "配送费" + deliCharge + "元");
                        }
                    }
                }
                break;
                case 2: {
                    System.out.println("查看餐袋");
                    System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");
                    for (int i = 0; names[i] != null; i++) {

                        String sta = (states[i] == 1) ? "已完成" : "已预定";

                        System.out.print((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + times[i] + "\t" + addresses[i] + "\t" + sumPrices[i] + "\t" + sta + "");

                    }

                }
                break;
                case 3: {
                    System.out.println("***签收定单***");

                    System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");

                    for (int i = 0; names[i] != null; i++) {

                        String sta = (states[i] == 1) ? "已完成" : "已预定";

                        System.out.print((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + times[i] + "\t" + addresses[i] + "\t" + sumPrices[i] + "\t" + sta + "");

                    }

                    System.out.print("请选择要签收的订单序号：");

                    int n = sc.nextInt();

                    states[n - 1] = 1;

                    System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");

                    for (int i = 0; names[i] != null; i++) {

                        String sta = (states[i] == 1) ? "已完成" : "已预定";

                        System.out.print((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + times[i] + "\t" + addresses[i] + "\t" + sumPrices[i] + "\t" + sta + "");
                    }
                }
                break;
                case 4: {
                    System.out.println("***删除订单***");

                    System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");

                    for (int i = 0; i < 4; i++) {

                        String sta = (states[i] == 1) ? "已完成" : "已预定";

                        System.out.print((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + times[i] + "\t" + addresses[i] + "\t" + sumPrices[i] + "\t" + sta + "");

                    }

                    System.out.print("请输入要删除的订单序号:");

                    int m = sc.nextInt();

                    for (int k = m; k < 4; k++) {

                        names[k - 1] = names[k];

                        dishMegs[k - 1] = dishMegs[k];

                        times[k - 1] = times[k];

                        addresses[k - 1] = addresses[k];

                        sumPrices[k - 1] = sumPrices[k];

                        states[k - 1] = states[k];

                    }

                    System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");

                    for (int i = 0; i < 4; i++) {

                        String sta = (states[i] == 1) ? "已完成" : "已预定";

                        System.out.print((i + 1) + "\t" + names[i] + "\t" + dishMegs[i] + "\t" + times[i] + "\t" + addresses[i] + "\t" + sumPrices[i] + "\t" + sta + "");
                    }
                }
                break;
                case 5: {
                    System.out.println("***我要点赞***");


                    System.out.println("序号" + "\t" + "菜名" + "\t" + "单价");

                    for (int i = 0; i < dishNames.length; i++) {

                        System.out.print(i + 1 + "\t" + dishNames[i] + "\t" + dishPrice[i] + "\t" + dianzan[i] + "赞" + "");

                    }

                    System.out.print("请输入点赞序号：");

                    int number = sc.nextInt();

                    dianzan[number - 1] = dianzan[number - 1] + 1;

                    System.out.println("序号" + "\t" + "菜名" + "\t" + "单价");

                    for (int i = 0; i < dianzan.length; i++) {

                        System.out.print(i + 1 + "\t" + dishNames[i] + "\t" + dianzan[i] + "\t" + dianzan[i] + "赞" + "");

                    }
                }
                break;
                case 6: {
                    System.out.println("退出系统");
                    return;
                }

            }
        } while (in == 0);

        System.out.println("谢谢使用，欢迎下次光临！");
    }
}
